let tags = document.getElementsByClassName("a-tag");
let input_submit=document.getElementsByClassName("input_submit")[0];
let input_keyboard=document.getElementById("keyboard");
let li_blogs=document.getElementsByClassName("li_blog");
let a_pages=document.getElementsByClassName("a_pages");

for (let i = 0; i < tags.length; i++) {
    tags[i].onclick=function () {
        input_keyboard.value=trim(tags[i].innerHTML);
        input_submit.click();
    }
}

function trim(s){
    return s.replace(/(^\s*)|(\s*$)/g, "");
}

for (let i = 9; i <li_blogs.length ; i++) {
    li_blogs[i].style.display="none";
}

a_pages[0].style.backgroundColor="#c2c2c2";
for (let i = 0; i < a_pages.length; i++) {
    a_pages[i].onclick=function () {
        //先对页面博客的显示进行处理
        for (let j = 0; j <li_blogs.length ; j++) {
            if (j<parseInt(trim(a_pages[i].innerHTML))*9&&j>=(parseInt(trim(a_pages[i].innerHTML))-1)*9){
                li_blogs[j].style.display="block";
            }
            else {
                li_blogs[j].style.display="none";
            }
        }
        //对按钮颜色进行处理
        for (let j = 0; j < a_pages.length; j++) {
            if(j!=i){
                a_pages[j].style.backgroundColor="";
                a_pages[j].name="page_notClick"
            }
        }
        a_pages[i].style.backgroundColor="#c2c2c2";
        a_pages[i].name="page_Click"
    }
}

// 上一页
document.getElementsByClassName("a_last")[0].onclick=function () {
    let index=0;
    for (let i = 0; i < a_pages.length; i++) {
        if(a_pages[i].name=="page_Click"){
            index=i;
        }
    }
    if(index>0){
        a_pages[index-1].click();
    }
}

// 下一页
document.getElementsByClassName("a_next")[0].onclick=function () {
    let index=0;
    for (let i = 0; i < a_pages.length; i++) {
        if(a_pages[i].name=="page_Click"){
            index=i;
        }
    }
    if(index<a_pages.length-1){
        a_pages[index+1].click();
    }
}